package demo

import (
	"fmt"
	"time"
)

func say(msg string, ch chan string) {
	for i := 0; i < 3; i++ {
		ch <- msg // 发送消息到通道
		time.Sleep(time.Second)
	}
	close(ch) // 关闭通道
}

func TestGoRoutine() {
	ch := make(chan string)
	go say("Hello", ch)

	for msg := range ch { // 从通道接收消息
		fmt.Println(msg)
	}
}
